// 递归实现
class Solution
{
public:
    string countAndSay(int n)
    {
        if (n == 1)
            return "1";
        string ret = countAndSay(n - 1);
        string tem;
        for (int left = 0, right = 0; left < ret.size();)
        {
            while (ret[right] == ret[left])
            {
                right++;
            }
            tem += to_string(right - left);
            tem.push_back(ret[left]);
            left = right;
        }
        return tem;
    }
};

class Solution
{
public:
    string countAndSay(int n)
    {
        if (n == 1)
            return "1";
        string ret;
        for (int i = 2; i <= n; i++)
        {
            for (int left = 0, right = 0; left < ret.size();)
            {
                while (ret[right] == ret[left])
                {
                    right++;
                }
                tem += to_string(right - left);
                tem.push_back(ret[left]);
                left = right;
            }
        }
    }
};


class Solution
{
public:
    string countAndSay(int n)
    {
        if (n == 1)
            return "1";
        string ret="1";
        for (int i = 2; i <= n; i++)
        {
            string tem;
            for (int left = 0, right = 0; left < ret.size();)
            {
                while (ret[right] == ret[left])
                {
                    right++;
                }
                tem += to_string(right - left);
                tem.push_back(ret[left]);
                left = right;
            }
            ret=tem;

        }
        return ret;
    }
};